import React from 'react';
import { connect } from 'dva';
import ReactEcharts from 'echarts-for-react';
import echarts from 'echarts/lib/echarts';
import { Button } from 'antd';

// function AutomaticEcharts ({dataArr,xData,dataArr1,dataArr2,dataArr3,dataArr4,dataArr5,dataArr6,dataArr7,data,dispatch}){
class Maximum extends React.Component {
    constructor(props){
        super(props);
        this.state = {
        
        };

    }

    
    componentDidMount() {
        // 基于准备好的dom，初始化echarts实例
        const { dataArr,dataArr1,dataArr2,dataArr3,dataArr4,dataArr5,dataArr6,dataArr7 } = this.props;
        
        var myChart = echarts.init(document.getElementById('main'));
        function arrMaxNum(arr){
          return Math.max.apply(null,arr);
      }
      
      function arrMinNum(arr){
        return Math.min.apply(null,arr);
      }
      function arrAverageNum(arr){
          var sum = 0;
          for (var i = 0; i < arr.length; i++) {
              sum += arr[i];
          };
          return ~~(sum/arr.length*10000)/10000;
      }
       var average =[];
       var maxArr = [];
       var minArr =[];

       average.push(arrAverageNum(dataArr));
       maxArr.push(arrMaxNum(dataArr));
       minArr.push(arrMinNum(dataArr));       
       average.push(arrAverageNum(dataArr1));
       maxArr.push(arrMaxNum(dataArr1));
       minArr.push(arrMinNum(dataArr1));  
       average.push(arrAverageNum(dataArr2));
       maxArr.push(arrMaxNum(dataArr2));
       minArr.push(arrMinNum(dataArr2));  
       average.push(arrAverageNum(dataArr3));
       maxArr.push(arrMaxNum(dataArr3));
       minArr.push(arrMinNum(dataArr3));  
       average.push(arrAverageNum(dataArr4));
       maxArr.push(arrMaxNum(dataArr4));
       minArr.push(arrMinNum(dataArr4));  
       average.push(arrAverageNum(dataArr5));
       maxArr.push(arrMaxNum(dataArr5));
       minArr.push(arrMinNum(dataArr5));  
       average.push(arrAverageNum(dataArr6));
       maxArr.push(arrMaxNum(dataArr6));
       minArr.push(arrMinNum(dataArr6));  
       average.push(arrAverageNum(dataArr7));
       maxArr.push(arrMaxNum(dataArr7));
       minArr.push(arrMinNum(dataArr7));  
      
        // 指定图表的配置项和数据
       
        var  option = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross',
                    crossStyle: {
                        color: '#999'
                    }
                }
            },
            toolbox: {
                feature: {
                    dataView: {show: true, readOnly: false},
                    magicType: {show: true, type: ['line', 'bar']},
                    restore: {show: true},
                    saveAsImage: {show: true}
                }
            },
            legend: {
                data:['最大值','最小值',]
            },
            xAxis: [
                {
                    type: 'category',
                    data: ['曲线','曲线1','曲线2','曲线3','曲线4','曲线5','曲线6','曲线7',],
                    axisPointer: {
                        type: 'shadow'
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    name: '数值',
        
                    axisLabel: {
                        formatter: '{value} '
                    }
                }
            ],
            series: [
                {
                    name:'最大值',
                    type:'bar',
                    data:maxArr
                },
                {
                    name:'最小值',
                    type:'bar',
                    data:minArr
                }
            ]
        };
      
        myChart.setOption(option);
    
         
     
    }
  
    
    render() {
        return (
            <div>

                <div id="main" style={{ width: 1600, height: 700 }}></div>

            </div>

        );
    }
}
// export default LineMarkerEcharts;
export default connect(({ echart }) => ({ ...echart }))(Maximum)